package com.ssl.commonutils;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

/**
 * 描述：执行命令返回值
 *
 * @author ssl
 * @create 2017/12/12 11:05
 */
public class CommandResult {
    int ret = 0;
    List<String> outLines;
    List<String> errLines;
    IOException exception;
    String command;

    public CommandResult() {
    }

    public int getRet() {
        return this.ret;
    }

    public void setRet(int ret) {
        this.ret = ret;
    }

    public List<String> getOutLines() {
        return this.outLines;
    }

    public void setOutLines(List<String> outLines) {
        this.outLines = outLines;
    }

    public List<String> getErrLines() {
        return this.errLines;
    }

    public void setErrLines(List<String> errLines) {
        this.errLines = errLines;
    }

    public IOException getIOException() {
        return this.exception;
    }

    public void setIOException(IOException exception) {
        this.exception = exception;
    }

    public String getCommand() {
        return this.command;
    }

    public void setCommand(String command) {
        this.command = command;
    }

    public String getOutput() {
        StringBuffer output = new StringBuffer();
        Iterator var2 = this.outLines.iterator();

        String line;
        while (var2.hasNext()) {
            line = (String) var2.next();
            if (trimToNull(line) != null) {
                output.append(line).append("\r\n");
            }
        }

        var2 = this.errLines.iterator();

        while (var2.hasNext()) {
            line = (String) var2.next();
            if (trimToNull(line) != null) {
                output.append(line).append("\r\n");
            }
        }

        return output.toString();
    }

    public static String trimToNull(String str) {
        String ts = trim(str);
        return isEmpty(ts) ? null : ts;
    }

    public static String trim(String str) {
        return str == null ? null : str.trim();
    }

    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }
}
